import * as server from "../service/base.js";
import { getLocalData, setLocalData } from "../../utils/tools";

export default {
  namespaced: true,
  state: {
    token: getLocalData("token") ? getLocalData("token") : "",
    layoutData: []
  },
  mutations: {
    setToken(state, payload) {
      state.token = payload;
      setLocalData("token", payload);
    },
    SET_LAYOUT_DATA: (state, layoutData) => {
      Vue.set(state, "layoutData", layoutData);
    }
  },
  actions: {
    async login({ commit }, data) {
      const { token: res } = await server.login(data);
      console.log('我的登录数据',res);
      commit('setToken', res.token);
    },
    DISPOSE_LAYOUT_DATA({ commit }, { layoutData }) {
      // 处理layout数据
      commit("SET_LAYOUT_DATA", layoutData);
    },
    // 获取侧边框数据
    async getLayoutData({ commit }, { jobId }) {
      const { result: data } = await server.getLayoutData(jobId);
      commit("SET_LAYOUT_DATA", {
        layoutData: arrayToTree(data.sysMenus || [], "0"),
        sysMenuFuncs: data.sysMenuFuncs
      });
      return data.sysMenus;
    }
  },
  modules: {}
};
